package controller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import entity.Student;

@Controller
@RequestMapping("/demo")
public class DemoController {

	@RequestMapping("/arr.do")
	@ResponseBody
	//ResponseBody会自动的将返回结果的Javabean转换为json字符串发送到浏览器客户端
	//底层用了Jackson API
	public Object test1(){
		
		String[]arr={"李红鹤","熊大","熊二"};
		
		return arr;
		
	}
	
	
	@RequestMapping("/stu.do")
	@ResponseBody
	//将javaBean作为返回值,ResponseBody注解将bean转换
	//为Json字符串发送到浏览器端
	public Object test2(){
		
		Student stu = new Student();
		stu.setName("王五");
		stu.setAge(22);

		
		return stu;
		
	}
	
	
	
	@RequestMapping("/list.do")
	@ResponseBody
	public Object test3(){
		
		List<String> list=new ArrayList<String>();
		
		String str1="苍老师";	
		String str2="李红鹤";
		String str3="范传奇";
		
		list.add(str1);
		list.add(str2);
		list.add(str3);
		
		return list;
		
	}
	
	
	
	@RequestMapping("/map.do")
	@ResponseBody
	public Object test4(){
		
		Map<Object,Object> map = new LinkedHashMap<Object, Object>();
		
		map.put("name","张三");
		map.put("age",25);
		map.put("price",80.5);
		map.put(1,new Student("李四",25));
		return map;
		
	}
	
	@RequestMapping("/map2.do")
	@ResponseBody
	public Object test5(){
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		Map<String,Object> map = new LinkedHashMap<String, Object>();
		map.put("name","张三");
		map.put("age",25);
		map.put("price",80.5);
		list.add(map);
		
		map = new LinkedHashMap<String, Object>();
		map.put("name","李四");
		map.put("age",27);
		map.put("price",70.5);
		list.add(map);
		
		
		map = new LinkedHashMap<String, Object>();
		map.put("name","王五");
		map.put("age",20);
		map.put("price",90.5);
		list.add(map);
		
		
		return list;
		
	}
	
	
	
	

}
